--- 深圳建恒超声波流量计  modbus 协议9600,N dtype=18,addr=01H(默认)
module(..., package.seeall)
local logtag = "JH"
local dtu, udtu,addr,isIns = {}, {},1,true
function setDtu(_dtu, _udtu)
    dtu, udtu = _dtu, _udtu
    addr = udtu.addr and tonumber(udtu.addr) or 1
    sys.taskInit(init)
end
function _pro(d)
    local _, ins = pack.unpack(d:sub(6, 7)..d:sub(4, 5), ">f")
    local _, val = pack.unpack(d:sub(14, 15)..d:sub(12, 13), ">I")
    if isIns then 
        lcd.LCD_DATA[3]= "瞬时:"..ins
        isIns = false
    else
        lcd.LCD_DATA[3]= "累计:"..val
        isIns = true
    end
    usrdata.update({val, ins})
end
function init()
    sys.wait(200)
	while true do
        tools.modbus_send(3,addr,3,4,6)
        local res, d = sys.waitUntil("UART_READ_DONE_NEXT_3" , 5000)
        if res then
            if d then
                _pro(d)
            end
            sys.wait(5000)
        else
            lcd.LCD_DATA[3]=logtag.." READ TIMEOUT"
        end
	end
end
